package com.easyJava.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具类
 */
public class DateUtils {

    public static final String YYYY_MM_DD = "yyyy-MM-dd";

    public static final String _YYYY_MM_DD = "yyyy_MM_dd";

    public static final String _YYYYMMDD = "yyyy/MM/dd";


    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";


    /**
     * 格式化日期
     * @param date
     * @param pattern
     * @return
     */
    public static String format(Date date , String pattern){
        if(date == null) return null;
        return new SimpleDateFormat(pattern).format(date);
    }

    /**
     * 解析日期
     * @param date
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static Date parse(String date ,String pattern) throws ParseException {
        return new SimpleDateFormat(pattern).parse(date);
    }

}
